#pragma once
#include <fstream>
using namespace std;

class Map
{
protected:
	int m_height, m_width;
	char ** m_array;
public:
	Map():m_height(0),m_width(0),m_array(0){}

	int getHeight(){return m_height;}
	int getWidth(){return m_width;}
	int get(int x, int y)
	{
		return m_array[y][x];
	}
	int set(int x, int y, int a_value)
	{
		m_array[y][x] = a_value;
	}
	void load(const char * a_filename)
	{
		fstream name(a_filename);
		name >> m_width;
		name >> m_height;
		// allocate the 2D array
		m_array = new char * [m_height];
		for(int i = 0; i < m_height; ++i)
			m_array[i] = new char [m_width];

		char input;
		int y = 0, x = 0;
		while(!name.eof())
		{
			input = name.get();
			if(input == -1)
				break;
			if(input != '\n' && input != '\r')
			{
				m_array[y][x] = input;
				x++;
				if(x >= m_width)
				{
					x = 0;
					y++;
				}
			}
		}
		name.close();
	}
	void release()
	{
		for(int i = 0; i < m_height; ++i)
			delete [] m_array[i];
		delete [] m_array;
		m_array = 0;
	}
	~Map(){release();}
};
